package com.lingx.web.api.impl;

import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import com.google.common.collect.Sets;
import com.lingx.service.LingxService;
import com.lingx.service.UserService;
import com.lingx.utils.TokenUtils;
import com.lingx.web.api.IApi;

public abstract class AbstractAuthApi extends AbstractApi{
	@Resource
	private LingxService lingxService;
	@Resource
	private UserService userService;
	@Override
	public int before(Map<String, Object> params) {
		String token=IApi.getParamString(params, "lingxtoken", "");
		if(TokenUtils.verifyToken(token)) {
			String userid=TokenUtils.getTokenDataUserId(token);
			if( this.userService.isAuthApi(userid, String.valueOf(this.getApiCode()))) {
				return 0;
			}else {
				return 40002;//权限不足
			}
		}else {
			return 40001;//会话失效
		}
		
	}

	public boolean isLog() {
		return true;
	}
}
